
using System.Collections;
using Mistral.Interface.Features;
using Mistral.Plugins;

namespace Mistral.Plugin.ApplicationWindow
{
	class PluginDescriptorView : ITreeNodeDescriptor, IDataBinding
	{
		readonly PluginDescriptor _pluginDescriptor;

		public PluginDescriptorView( PluginDescriptor pluginDescriptor )
		{
			_pluginDescriptor = pluginDescriptor;
		}

		#region ITreeNodeDescriptor Members

		string ITreeNodeDescriptor.Name
		{
			get { return _pluginDescriptor.Name; }
		}

		public object Tag
		{
			get { return _pluginDescriptor; }
		}

		public IEnumerable Children
		{
			get { return null; }
		}

		#endregion

		#region DataBinding properties

		public enum Props
		{
			Name,
			Description,
			Path,
			Status,
			Startup,
			StartEnabled,
			StopEnabled
		}

		public string Name
		{
			get { return _pluginDescriptor.Name; }
		}
		
		public string Description
		{
			get
			{
				return _pluginDescriptor.Plugin.Info.Description;
			}
		}
		
		public string Path
		{
			get { return _pluginDescriptor.PluginType.Assembly.Location; }
		}
		
		public string Status
		{
			get { return _pluginDescriptor.Plugin.Status.ToString( ); }
		}
		
		public PluginStartup Startup
		{
			get { return _pluginDescriptor.PluginStartup; }
			set { _pluginDescriptor.PluginStartup = value; }
		}
		
		public bool StartEnabled
		{
			get
			{
				return new ArrayList(_pluginDescriptor.Plugin.AvailableCommands).Contains( PluginAction.Start );
			}
		}
		
		public bool StopEnabled
		{
			get
			{
				return new ArrayList(_pluginDescriptor.Plugin.AvailableCommands).Contains( PluginAction.Stop );
			}
		}
		
		public void OnStart()
		{
			App.Instance.PluginManager.ExecuteCommand( _pluginDescriptor.Plugin, PluginAction.Start, null );
		}
		
		public void OnStop()
		{
			App.Instance.PluginManager.ExecuteCommand( _pluginDescriptor.Plugin, PluginAction.Stop, null );
		}
		
		#endregion

	}
	
}
